import { LiveActionType } from '../actions/liveAction'

const live_state = {
  teacher_leave: false,
  pause: false,
  images: [],
  index: 0,
  voiceStatus: 0,
  showVideo: false
}

const LiveState = (state = live_state, action) => {
  switch (action.type) {
    case LiveActionType.add_image:
      const images = state.images.concat(action.image)
      const index = images.length - 1
      return Object.assign({}, state, {
        images: images,
        index: index
      })
    case LiveActionType.init_swiper:
      return Object.assign({}, state, {
        images: action.images,
        index: action.index
      })
    case LiveActionType.change_index:
      return Object.assign({}, state, {
        index: action.index
      })
    case LiveActionType.teacher_leave:
      return Object.assign({}, state, {
        teacher_live: action.leave
      })
    case LiveActionType.change_video_mask:
      console.log('LiveActionType.change_video_mask', action)
      return Object.assign({}, state, {
        showVideo: action.show
      })
    case LiveActionType.live_pause:
      return Object.assign({}, state, {
        pause: action.pause
      })
    case LiveActionType.change_voice_status:
      return Object.assign({}, state, {
        voiceStatus: action.status
      })
    default:
      return state
  }
}
LiveState._default_state = live_state
export default LiveState
